package com.smart.wap.h5;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.BaseSearch;
import com.smart.common.entities.core.Page;
import com.smart.manager.member.repository.MemberProfileAddressRepository;
import com.smart.manager.union.egg.models.UnionEggOrder;
import com.smart.manager.union.egg.repository.UnionEggOrderRepository;
import com.smart.utils.MemberAcl;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.OrderBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 会员资料信息接口
 *
 * @author Administrator
 */
@Api(tags = "公众号H5-提蛋订单")
@RestController
@RequestMapping(SmartConstant.WAP_API_PREFIX + "h5/egg")
@RequiredArgsConstructor
@Log4j2
public class EggController {

    private final UnionEggOrderRepository orderRepository;

    @ApiOperation(value = "获取我提蛋订单")
    @GetMapping(value = "getMyOrderList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Page<UnionEggOrder>> getMyOrderList(BaseSearch baseSearch) {
        Long memberId = MemberAcl.getLoginId();
        Page<UnionEggOrder> result = orderRepository.getMyPageList(memberId, baseSearch);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "修改订单地址")
    @PostMapping(value = "updateEggOrderAddress")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<String> updateEggOrderAddress(@Validated @RequestBody OrderBody.UpdateAddressBody body) {
        Long memberId = MemberAcl.getLoginId();
        orderRepository.updateEggOrderAddress(memberId, body);
        return AjaxResult.success("收货地址更新成功");
    }


}
